function [signal] = PAUSSignalExtract(bin_file_path, acq_parameter_file_path, modality, channels, valid_data_only, range)
% 提取选中channels和range的信号

% bin_file_path            :  原始数据bin文件路径，每个bin文件第一帧为光声信号，其余帧为超声信号，此bin文件需要在前端界面选择
% acq_parameter_file_path  ： 原始数据采集参数文件（.csv文件）的路径，前期用不到可忽略，无需在界面选择
% modality      :  成像模态，0为超声，1为光声
% channels      :  数组，选中的通道，选中通道的数据会被依次提取出来
% valid_data_only  :  int, 显示通道全部数据还是仅显示有效数据，1表示仅显示有效数据，0表示显示全部数据
% range            :  二元数组，有效数据的范围。当valid_data_only为1时需要设置此二元数组
% signal           ：结构体，信号相关参数mat(光声/超声可使用相同的格式)，相关参数包括selectedchannels(选中的通道号),pointnumber（每个信号包括的点数），signals(所有通道信号的一维数组)，x-axis-label(x轴显示信息，如mm)，y-axis-label（y轴显示信息，如mm），x-axis-tick-label（x轴上的刻度值，如[-15，15]），y-axis-tick-label(y轴上的刻度值，如[0，30，50，70])
% 超声：signal_extract = PAUSSignalExtract('E:\Projects\Test\Rawdata_FPGA1_Frame0.bin',1,0,[1 16 32 48 64],1,[8021 8520]);
% 光声：signal_extract = PAUSSignalExtract('E:\Projects\Test\Rawdata_FPGA1_Frame0.bin',1,1,[1 16 32 48 64],1,[4011 4510]); 

[Data_Rf, acqLen] = DataExtractFromBin(bin_file_path, 0);
Data_US_Rf = Data_Rf.US;
Data_PA_Rf = Data_Rf.PA;





if modality == 0
    % save([save_path,'Data_US_Rf_',datestr(now,30),'.mat'],'Data_US_Rf')

    for i=1:64
        for j=1:1
            cc0=double(Data_US_Rf(:,i,j));
            Alldata_US(:,i,j)=interp(cc0,5)';
        end
    end
    Alldata=mean(Alldata_US,3);

    [p,~]=size(Alldata);
    if valid_data_only == 1              %设置有效信号范围
        analysis_signals_length = range(1):range(2); %信号范围
    elseif valid_data_only == 0
        analysis_signals_length = 1:p;   %全部信号
        range = [1, p];
    end

    signalextract = Alldata(analysis_signals_length,channels);

    signal.signals = signalextract;      %选中通道的信号的转置
    signal.pointnumber = length(analysis_signals_length); %信号的点数 
    XAxisLabel = xlabel('Point','fontname', 'times new roman','fontSize',30);%设置坐标轴的标签字号大小(20)
    signal.XAxisTickLabel = range;         %x轴刻度
    YAxisLabel = ylabel('Amplitude (a. u.)','fontname', 'times new roman','fontSize',30);
    min_signal_value = min(signalextract);
    max_signal_value = max(signalextract);
    delta = (max_signal_value - min_signal_value) * 0.05;
    signal.YAxisTickLabel = [min_signal_value-delta,  max_signal_value+delta];     %y轴刻度
    signal.XAxisLabel = XAxisLabel.String;%x轴显示信息
    signal.YAxisLabel = YAxisLabel.String;%y轴显示信息
    signal.selectedchannels = channels;   %通道数

    close(gcf);

elseif modality == 1

    % save([save_path,'Data_PA_Rf_',datestr(now,30),'.mat'],'Data_PA_Rf');
    for i=1:64
        for j=1:1
            cc1=double(Data_PA_Rf(:,i,j));
            Alldata_PA(:,i,j)=interp(cc1,5)';
        end
    end
    % Alldata_before=filter(Hd,mean(Alldata_before,3));
    Alldata=mean(Alldata_PA,3);


    [p,~]=size(Alldata);
    if valid_data_only == 1
        analysis_signals_length = range(1):range(2); % 
    elseif valid_data_only == 0
        analysis_signals_length = 1:p;
        range = [1, p];
    end

    signalextract = Alldata(analysis_signals_length,channels);

    signal.signals = signalextract; 
    signal.pointnumber = length(analysis_signals_length);
    XAxisLabel = xlabel('Point','fontname', 'times new roman','fontSize',30);%设置坐标轴的标签字号大小(20)
    signal.XAxisTickLabel = range;
    YAxisLabel = ylabel('Amplitude (a. u.)','fontname', 'times new roman','fontSize',30);
    min_signal_value = min(signalextract);
    max_signal_value = max(signalextract);
    delta = (max_signal_value - min_signal_value) * 0.05;
    signal.YAxisTickLabel = [min_signal_value-delta,  max_signal_value+delta];     %y轴刻度
    signal.XAxisLabel = XAxisLabel.String;
    signal.YAxisLabel = YAxisLabel.String;
    signal.selectedchannels = channels;
    
    close(gcf);


end

if valid_data_only == 1 && modality == 0            %设置有效信号范围
    figure;
    plot([1:100]);

    figure;
    plot(signalextract);



end

if valid_data_only == 1 && modality == 1            %设置有效信号范围
    figure;
    plot([1:100]);

    figure;
    plot(signalextract);


    figure;

end


end






